using Webshop20.Application;
using Webshop20.Application.Operations.Messages;

namespace Webshop20.Usecases.States.Registration
{
    public class UpdateAccountState : IRegistrationState
    {
        private readonly IService updateAccountInProgressService;

        public UpdateAccountState(IService updateAccountInProgressService)
        {
            this.updateAccountInProgressService = updateAccountInProgressService;
        }

        #region IRegistrationState Members

        public string UpdateAccount(IUseCaseStateContext stateContext, UpdateTransientNewRegistrationDataRequest request)
        {
            request.AccountInterimsKey = stateContext.GetSessionObject("AccountInterimKey").ToString();

            var updateAccountInProgressResponse =
                updateAccountInProgressService.Handle(request) as UpdateTransientAccountResponse;

            if (updateAccountInProgressResponse.DomainMessage != null)
            {
                stateContext.AddErrorMessagesToViewDataModelState(updateAccountInProgressResponse.DomainMessage);
                return Views.INDEX;
            }

            return Views.OVERVIEW;
        }

        #endregion


    }
}